package org.example.demo20240504.api;

import cn.hutool.core.util.IdUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.example.demo20240504.mq.DemoOutput;
import org.example.demo20240504.mq.dto.OrderDTO;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName DemoApi
 * @Description TODO
 * @Author huarujin
 * @Date 2024/5/4 15:15
 * @Version 1.0
 */

@RestController
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/demo")
public class DemoApi {

    private final DemoOutput demoOutput;

    @PostMapping("/send")
    public String sendMsg(@RequestBody OrderDTO orderDTO) {
        // 此时订单状态修改为已完成
        orderDTO.setOrderId(IdUtil.getSnowflakeNextId());
        // 通知库存进行数量扣减
        demoOutput.sendMsg(orderDTO);
        return "成功";
    }

}
